package logic;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Degree {
	public static final String KEY_ID = "degree_key";
	public static final String NAME = "name";
	public static final String UNI_KEY = "id_uni";
	private String id;
	private String name;
	private String idUni;

	public Degree(String id, String name, String uni) {
		this.id = id;
		this.name = name;
		this.setIdUni(uni);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public static ArrayList<Degree> getDegreesFromJSON(String JSON) {
		ArrayList<Degree> degrees = new ArrayList<Degree>();
		try {
			//JSONObject Object = new JSONObject(JSON);
			JSONArray jsonArray = new JSONArray(JSON);
			for(int i = 0; i < jsonArray.length(); i++ ){
        		JSONObject jsonObject = jsonArray.getJSONObject(i);
        		String id = jsonObject.getString("id_carrera");
        		String name = jsonObject.getString("nombre");
        		String uni = jsonObject.getString("id_uni");
        		
        		degrees.add(new Degree(id, name, uni));
        	}
			return degrees;
		} 
		catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
	}

	public String getIdUni() {
		return idUni;
	}

	public void setIdUni(String idUni) {
		this.idUni = idUni;
	}
}
